/**
 * Created by a1 on 16/4/25.
 */

function onload() {
    if(navigator.cookieEnabled) {
        alert("Cookie 已启用!")
    }else {
        alert("Cookie 不可用!")
    }
}

function change() {
    person = new Object()
    person.name = "Milo"
    person.age = 30

    var p = document.getElementById("p")
    p.innerHTML = "name: " + person.name + "<br/>" + "age: " + person.age
    p.style.color = "#abcdef"
    p.style.backgroundColor = "#fedcba"
}

function changeImage() {
    var img = document.getElementById("img")
    var index = img.src.indexOf("/image/")
    if (index > 0) {
        img.src = "http://cdn.duitang.com/uploads/blog/201508/22/20150822112822_8VxQE.jpeg"
    }else {
        img.src = "../image/riven.jpg"
    }
}

function check() {
    var text = document.getElementById("input_text").value
    if (text == "" || isNaN(text)) {
        alert("Not Number")
    }
}

function timing() {
    var t = setTimeout("alert('3s')", 3000)
}

var isTiming = false
var c = 0
var t

function switchTime() {
    if(!isTiming) {
        alert("开始计时")
        isTiming = true
        document.getElementById("switchTime").value = "停止计时"
        timeCount()
    }else {
        alert("停止计时")
        isTiming = false
        document.getElementById("switchTime").value = "开始计时"
        timeEnd()
    }
}

function timeCount() {
    document.getElementById("Time").innerHTML = c
    t = setTimeout("timeCount()", 1000)
    c += 1
}

function timeEnd() {
    c = 0
    document.getElementById("Time").innerHTML = c
    clearTimeout(t)
}
